﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using CarLoanSystem.Entity;

namespace CarLoanSystem
{
    public partial class frmCheckAppoint : Form
    {
        public frmCheckAppoint()
        {
            InitializeComponent();
            this.lblStatus.Text = "";
            this.lblStatus.Update();
        }

        public void CheckAppoint()
        {
            DateTime date = DateTime.Now;
            DataTable dt = DAL.AppointmentsInfoDAL.LoadAppointmentForCheck(date.Year + "-" + date.Month + "-" + date.Day);
            if (dt == null)
            {
                progressBar.Maximum = 1;
                progressBar.Step = 1;
            }
            else
            {
                progressBar.Maximum = dt.Rows.Count;
                progressBar.Step = 1;
                LoanItem loanItem;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    loanItem = new LoanItem();
                    loanItem.LOAN_ID = Convert.ToInt32(dt.Rows[i]["LOAN_ID"].ToString());
                    loanItem.LOAN_STATUS = "F";
                    DAL.LoanInfoDAL.Update(loanItem);
                    progressBar.PerformStep();
                }
            }
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            this.lblStatus.Text = "กำลังทำงาน";
            this.lblStatus.Update();
            CheckAppoint();
            this.lblStatus.Text = "ทำงานเสร็จสิ้น";
            this.lblStatus.Update();
        }
    }
}
